home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / chat / reflect.000 / reflect / 3.0b3 / load.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  30.5 KB  |  1,226 lines

  1. /*
  2.  
  3. Copyright 1993, 1994, Cornell University
  4.  
  5. Cornell hereby grants permission to use, copy, modify, and distribute this program for any purpose 
  6. and without fee, provided that these copyright and permission notices appear on all copies and 
  7. supporting documentation, the name of Cornell not be used in advertising or publicity pertaining 
  8. to distribution of the program without specific prior permission, notice be given in supporting 
  9. documentation that copying and distribution is by permission of Cornell.  CORNELL MAKES NO 
  10. REPRESENTATIONS OR WARRANTEES, EXPRESS OR IMPLIED.  By way of example, but not limitation, 
  11. CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR 
  12. PURPOSE OR THAT THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, 
  13. TRADEMARKS, OR OTHER RIGHTS.  Cornell shall not be held liable for any liability with respect to 
  14. any claim by the user or any other party arising from use of the program.
  15.  
  16. This material is partially based on work sponsored by the National Science Foundation under Cooperative 
  17. Agreement No. NCR-9318337.  The government has certain rights in this material.
  18.  
  19. */
  20.  
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <signal.h>
  25. #include <errno.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28.  
  29. #ifndef LINUX
  30. #include <sys/socketvar.h>
  31. #endif
  32.  
  33. #include <netinet/in.h>
  34. #include <arpa/inet.h>
  35.  
  36. #include "reflect.h"
  37. #include "refmon.h"
  38. #include "globals.h"
  39.  
  40. unsigned short clincnt = 1;
  41.  
  42. FILE  *conf_fd;
  43. short scan_str();
  44.  
  45. load_config(fname)
  46.    char *fname;
  47. {
  48.    int            icnt;
  49.    char           code[30],line[101],buf[100],*configfile = CONFIGFILE;
  50.    int            cnt,hb,mh,ml,lb,id;
  51.    char           *tmp;
  52.    short          status;
  53.  
  54.    if (fname != NULL) 
  55.       configfile = fname; 
  56.  
  57.    printf("\nVersion: %s\n",VERSION_STRING);
  58.  
  59.    if ((conf_fd = fopen (configfile, "r")) == NULL)
  60.       return;
  61.  
  62.    tmp = conf_buf;
  63.  
  64.    while (!feof (conf_fd)) 
  65.    {
  66.       if ((code[0] = fgetc(conf_fd)) <= ' ') 
  67.       {
  68.          if (code[0] == '\n')
  69.             ++clincnt;
  70.          continue;
  71.       }
  72.  
  73.       if ((icnt = fscanf (conf_fd, "%s", code + 1)) == EOF)
  74.          break;
  75.  
  76.       if (icnt != 1)
  77.       {
  78.          printf("Unable to parse configuration code line %d\n",clincnt);
  79.          exit(-1);
  80.       }
  81.  
  82.       if (code[0] == ';')
  83.       {
  84.          fgets (line, 100, conf_fd);
  85.          ++clincnt;
  86.          continue;
  87.       }
  88.  
  89.       printf("\n%d: ",clincnt);
  90.  
  91.       printf("%s ",code);
  92.  
  93.  
  94.       if (strcasecmp (code, "DEBUG") == 0) 
  95.       {
  96.          strcpy(tmp,"debug\n ");
  97.          tmp += strlen(tmp);
  98.          debug = 1;
  99.          continue;
  100.       }
  101.  
  102.       if (strcasecmp(code, "NV-UC-PORT") == 0) 
  103.       {
  104.          strcpy(tmp,"nv-uc-port ");
  105.          tmp += strlen(tmp);
  106.  
  107.          if ((cnt = fscanf(conf_fd, " %i", &nv_ucast_port)) != 1)
  108.          {
  109.             printf ("NV-UC-PORT paramater count error\n");
  110.             exit(-1);
  111.          }
  112.  
  113.          printf("%d ",nv_ucast_port);
  114.          sprintf(buf,"%d ",nv_ucast_port);
  115.  
  116.          sprintf(tmp,"%d\n",nv_ucast_port);
  117.          tmp += strlen(tmp);
  118.  
  119.          continue;
  120.       }
  121.  
  122.  
  123.       if (strcasecmp(code, "NV-MC-PORT") == 0)
  124.       {
  125. #ifdef MULTI
  126.          strcpy(tmp,"nv-mc-port ");
  127.          tmp += strlen(tmp);
  128.  
  129.          if ((cnt = fscanf(conf_fd, " %i", &nv_mcast_port)) != 1)
  130.          {
  131.             printf ("NV-PORT paramater count error\n");
  132.             exit(-1);
  133.          }
  134.  
  135.          printf("%d ",nv_mcast_port);
  136.          sprintf(buf,"%d ",nv_mcast_port);
  137.  
  138.          sprintf(tmp,"%d\n",nv_mcast_port);
  139.          tmp += strlen(tmp);
  140.  
  141.          nv_out_mcast.sin_port = htons(nv_mcast_port);
  142.          nv_in_mcast.sin_port = htons(nv_mcast_port);
  143. #else
  144.          printf ("This copy of the reflector was not built with Multicast support\n");
  145.          exit(-1);
  146. #endif
  147.          continue;
  148.       }
  149.  
  150.  
  151.       if (strcasecmp(code, "NV-MC-IN") == 0)
  152.       {
  153. #ifdef MULTI
  154.          strcpy(tmp,"nv-mc-in ");
  155.          tmp += strlen(tmp);
  156.  
  157.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  158.          {
  159.             printf ("NV-MC-IN paramater count error\n", cnt);
  160.             exit(-1);
  161.          }
  162.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  163.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  164.  
  165.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  166.          tmp += strlen(tmp);
  167.  
  168.          if ((nv_in_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  169.          {
  170.             printf("inet_addr: bad NV-MC-IN multicast address\n");
  171.             exit(-1);
  172.          }
  173.          nv_in_mcast.sin_family = AF_INET;
  174. #else
  175.          printf ("This copy of the reflector was not built with Multicast support\n");
  176.          exit(-1);
  177. #endif
  178.          continue;
  179.       }
  180.  
  181.       if (strcasecmp(code, "NV-MC-OUT") == 0)
  182.       {
  183. #ifdef MULTI
  184.          strcpy(tmp,"nv-mc-out ");
  185.          tmp += strlen(tmp);
  186.          if ((cnt = fscanf(conf_fd, "%i %i.%i.%i.%i",&nv_ttl,&hb,&mh,&ml,&lb)) != 5)
  187.          {
  188.             printf ("NV-MC-OUT paramater count error\n");
  189.             exit(-1);
  190.          }
  191.          printf("%d %d.%d.%d.%d ",nv_ttl,hb,mh,ml,lb);
  192.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  193.  
  194.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  195.          tmp += strlen(tmp);
  196.  
  197.          if ((nv_out_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  198.          {
  199.             printf("inet_addr: bad NV-MC-OUT multicast address\n");
  200.             exit(-1);
  201.          }
  202.          nv_out_mcast.sin_family = AF_INET;
  203. #else
  204.          printf ("This copy of the reflector was not built with Multicast support\n");
  205.          exit(-1);
  206. #endif
  207.          continue;
  208.       }
  209.  
  210.       if (strcasecmp(code, "MC-OUT") == 0) 
  211.       {
  212. #ifdef MULTI
  213.          strcpy(tmp,"mc-out ");
  214.          tmp += strlen(tmp);
  215.  
  216.          if ((cnt = fscanf(conf_fd, "%i %i.%i.%i.%i",&rf_ttl,&hb,&mh,&ml,&lb)) != 5)
  217.          {
  218.             printf ("MC-OUT-out paramater count error\n");
  219.             exit(-1);
  220.          }
  221.          printf("%d %d.%d.%d.%d ",rf_ttl,hb,mh,ml,lb);
  222.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  223.  
  224.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  225.          tmp += strlen(tmp);
  226.  
  227.          if ((rfout_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  228.          {
  229.             printf("inet_addr: bad MC-OUT multicast address\n");
  230.             exit(-1);
  231.          }
  232.          rfout_mcast.sin_family = AF_INET;
  233.          rfout_mcast.sin_port = htons(RF_PORT);
  234. #else
  235.          printf ("This copy of the reflector was not built with Multicast support\n");
  236.          exit(-1);
  237. #endif
  238.          continue;
  239.       }
  240.  
  241.       if (strcasecmp(code, "MC-IN") == 0) 
  242.       {
  243. #ifdef MULTI
  244.          strcpy(tmp,"mc-in ");
  245.          tmp += strlen(tmp);
  246.  
  247.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  248.          {
  249.             printf ("MC-IN paramater count error\n", cnt);
  250.             exit(-1);
  251.          }
  252.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  253.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  254.  
  255.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  256.          tmp += strlen(tmp);
  257.  
  258.          if ((rfin_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  259.          {
  260.             printf("inet_addr: bad MC-IN multicast address\n");
  261.             exit(-1);
  262.          }
  263.          rfin_mcast.sin_family = AF_INET;
  264.          rfin_mcast.sin_port = htons(RF_PORT);
  265. #else
  266.          printf ("This copy of the reflector was not built with Multicast support\n");
  267.          exit(-1);
  268. #endif
  269.          continue;
  270.       }
  271.  
  272.       if (strcasecmp(code, "MC-GROUP") == 0) 
  273.       {
  274. #ifdef MULTI
  275.          strcpy(tmp,"mc-group ");
  276.          tmp += strlen(tmp);
  277.  
  278.          if ((cnt = fscanf(conf_fd, "%i %i.%i.%i.%i",&inout_ttl,&hb,&mh,&ml,&lb)) != 5)
  279.          {
  280.             printf ("MC-GROUP paramater count error\n");
  281.             exit(-1);
  282.          }
  283.          printf("%d %d.%d.%d.%d ",inout_ttl,hb,mh,ml,lb);
  284.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  285.  
  286.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  287.          tmp += strlen(tmp);
  288.  
  289.          if ((inout_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  290.          {
  291.             printf("inet_addr: bad MC-GROUP multicast address\n");
  292.             exit(-1);
  293.          }
  294.          inout_mcast.sin_family = AF_INET;
  295.          inout_mcast.sin_port = htons(RF_PORT);
  296. #else
  297.          printf ("This copy of the reflector was not built with Multicast support\n");
  298.          exit(-1);
  299. #endif
  300.          continue;
  301.       }
  302.  
  303.       if (strcasecmp(code, "MAX-PARTICIPANTS") == 0) 
  304.       {
  305.          strcpy(tmp,"max-participants ");
  306.          tmp += strlen(tmp);
  307.  
  308.          if ((cnt = fscanf(conf_fd, "%i",&maxallowed)) != 1)
  309.          {
  310.             printf ("MAX-PARTICIPANTS paramater count error\n");
  311.             exit(-1);
  312.          }
  313.          printf("%d ",maxallowed);
  314.          sprintf(buf,"%d ",maxallowed);
  315.  
  316.          sprintf(tmp,"%d",maxallowed);
  317.          tmp += strlen(tmp);
  318.  
  319.          if (maxallowed > MAXCLIENT)
  320.          {
  321.             printf("Maximum number of clients allowed is %d\n",MAXCLIENT);
  322.             maxallowed = MAXCLIENT;
  323.          }
  324.  
  325.          status = scan_str(mp_buf,MSGBUF);
  326.  
  327.          if (status == -1)
  328.          {
  329.             printf ("max-participants message string does not end with // \n");
  330.             exit(-1);
  331.          }
  332.  
  333.          if (status == -2)
  334.          {
  335.             printf ("max-participants message length is greater then %d characters \n",MSGBUF);
  336.             exit(-1);
  337.          }
  338.  
  339.          sprintf(tmp,"%s\n",mp_buf);
  340.          tmp += strlen(tmp);
  341.          continue;
  342.  
  343.       }
  344.  
  345.       if (strcasecmp(code, "MAX-SENDERS") == 0) 
  346.       {
  347.          strcpy(tmp,"max-senders ");
  348.          tmp += strlen(tmp);
  349.  
  350.          if ((cnt = fscanf(conf_fd, "%i",&maxsenders)) != 1)
  351.          {
  352.             printf ("MAX-SENDERS paramater count error\n");
  353.             exit(-1);
  354.          }
  355.          printf("%d ",maxsenders);
  356.          sprintf(buf,"%d ",maxsenders);
  357.  
  358.          sprintf(tmp,"%d",maxsenders);
  359.          tmp += strlen(tmp);
  360.  
  361.          if (maxsenders > MAXCLIENT)
  362.          {
  363.             printf("Maximum number of clients allowed is %d\n",MAXCLIENT);
  364.         exit(-1);
  365.          }
  366.  
  367.          status = scan_str(ms_buf,MSGBUF);
  368.  
  369.          if (status == -1)
  370.          {
  371.             printf ("max-senders message string does not end with // \n");
  372.             exit(-1);
  373.          }
  374.  
  375.          if (status == -2)
  376.          {
  377.             printf ("max-senders message length is greater then %d characters \n",MSGBUF);
  378.             exit(-1);
  379.          }
  380.  
  381.          sprintf(tmp,"%s\n",ms_buf);
  382.          tmp += strlen(tmp);
  383.          continue;
  384.       }
  385.  
  386.       if (strcasecmp(code, "MAX-LURKERS") == 0) 
  387.       {
  388.          strcpy(tmp,"max-lurkers ");
  389.          tmp += strlen(tmp);
  390.  
  391.          if ((cnt = fscanf(conf_fd, "%i",&maxlurkers)) != 1)
  392.          {
  393.             printf ("MAX-LURKERS paramater count error\n");
  394.             exit(-1);
  395.          }
  396.          printf("%d ",maxlurkers);
  397.          sprintf(buf,"%d ",maxlurkers);
  398.  
  399.          sprintf(tmp,"%d",maxlurkers);
  400.          tmp += strlen(tmp);
  401.  
  402.          if (maxlurkers > MAXCLIENT)
  403.          {
  404.             printf("Maximum number of clients allowed is %d\n",MAXCLIENT);
  405.         exit(-1);
  406.          }
  407.  
  408.          status = scan_str(ml_buf,MSGBUF);
  409.  
  410.          if (status == -1)
  411.          {
  412.             printf ("max-lurkers message string does not end with // \n");
  413.             exit(-1);
  414.          }
  415.  
  416.          if (status == -2)
  417.          {
  418.             printf ("max-lurkers message length is greater then %d characters \n",MSGBUF);
  419.             exit(-1);
  420.          }
  421.  
  422.          sprintf(tmp,"%s\n",ml_buf);
  423.          tmp += strlen(tmp);
  424.          continue;
  425.       }
  426.  
  427.       if (strcasecmp(code, "MIN-MAC-VERSION") == 0) 
  428.       {
  429.          strcpy(tmp,"min-mac-version ");
  430.          tmp += strlen(tmp);
  431.  
  432.          if ((cnt = fscanf(conf_fd, "%i",&min_mac_version)) != 1)
  433.          {
  434.             printf ("MIN-MAC-VERSION paramater count error\n");
  435.             exit(-1);
  436.          }
  437.          printf("%d ",min_mac_version);
  438.  
  439.          sprintf(buf,"%d ",min_mac_version);
  440.  
  441.          sprintf(tmp,"%d ",min_mac_version);
  442.          tmp += strlen(tmp);
  443.  
  444.          status = scan_str(mv_mac_buf,MSGBUF);
  445.  
  446.          if (status == -1)
  447.          {
  448.             printf ("min-mac-version message string does not end with // \n");
  449.             exit(-1);
  450.          }
  451.  
  452.          if (status == -2)
  453.          {
  454.             printf ("min-mac-version message length is greater then %d characters \n",MSGBUF);
  455.             exit(-1);
  456.          }
  457.  
  458.          sprintf(tmp,"%s\n",mv_mac_buf);
  459.          tmp += strlen(tmp);
  460.  
  461.          continue;
  462.       }
  463.  
  464.       if (strcasecmp(code, "MIN-PC-VERSION") == 0) 
  465.       {
  466.          strcpy(tmp,"min-pc-version ");
  467.          tmp += strlen(tmp);
  468.  
  469.          if ((cnt = fscanf(conf_fd, "%i",&min_pc_version)) != 1)
  470.          {
  471.             printf ("MIN-PC-VERSION paramater count error\n");
  472.             exit(-1);
  473.          }
  474.          printf("%d ",min_pc_version);
  475.  
  476.          sprintf(buf,"%d ",min_pc_version);
  477.  
  478.          sprintf(tmp,"%d ",min_pc_version);
  479.          tmp += strlen(tmp);
  480.  
  481.          status = scan_str(mv_pc_buf,MSGBUF);
  482.  
  483.          if (status == -1)
  484.          {
  485.             printf ("min-pc-version message string does not end with // \n");
  486.             exit(-1);
  487.          }
  488.  
  489.          if (status == -2)
  490.          {
  491.             printf ("min-pc-version message length is greater then %d characters \n",MSGBUF);
  492.             exit(-1);
  493.          }
  494.  
  495.          sprintf(tmp,"%s\n",mv_pc_buf);
  496.          tmp += strlen(tmp);
  497.  
  498.          continue;
  499.       }
  500.  
  501.       if (strcasecmp(code, "REFMON") == 0) 
  502.       {
  503.          strcpy(tmp,"refmon ");
  504.          tmp += strlen(tmp);
  505.  
  506.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  507.          {
  508.             printf ("REFMON paramater count error\n");
  509.             exit(-1);
  510.          }
  511.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  512.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  513.          
  514.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  515.          tmp += strlen(tmp);
  516.  
  517.          if ((control_ip = inet_addr(buf)) == -1)
  518.          {
  519.             printf("inet_addr: bad REFMON address\n");
  520.             exit(-1);
  521.          }
  522.          continue;
  523.       }
  524.  
  525.       if (strcasecmp(code, "ADMIT-GENERAL-BCC") == 0) 
  526.       {
  527.          strcpy(tmp,"admit-general-bcc ");
  528.          tmp += strlen(tmp);
  529.  
  530.          if ((cnt = fscanf(conf_fd, "%i %i",&gbcc_cnt,&gbcc_id)) != 2)
  531.          {
  532.             printf ("ADMIT-GENERAL-BCC paramater count error\n");
  533.             exit(-1);
  534.          }
  535.          printf("%d %d ",gbcc_cnt,gbcc_id);
  536.  
  537.          sprintf(tmp,"%d %d ",gbcc_cnt,gbcc_id);
  538.          tmp += strlen(tmp);
  539.  
  540.          continue;
  541.       }
  542.  
  543.       if (strcasecmp(code, "CONF-ID") == 0) 
  544.       {
  545.          strcpy(tmp,"conf-id ");
  546.          tmp += strlen(tmp);
  547.  
  548.          if ((cnt = fscanf(conf_fd, "%i",&conference_id)) != 1)
  549.          {
  550.             printf ("CONF-ID paramater count error\n");
  551.             exit(-1);
  552.          }
  553.          printf("%d ",conference_id);
  554.  
  555.          sprintf(tmp,"%d ",conference_id);
  556.          tmp += strlen(tmp);
  557.  
  558.          status = scan_str(ci_buf,MSGBUF);
  559.  
  560.          if (status == -1)
  561.          {
  562.             printf ("conf-id message string does not end with // \n");
  563.             exit(-1);
  564.          }
  565.  
  566.          if (status == -2)
  567.          {
  568.             printf ("conf-id message length is greater then %d characters \n",MSGBUF);
  569.             exit(-1);
  570.          }
  571.  
  572.          sprintf(tmp,"%s\n",ci_buf);
  573.          tmp += strlen(tmp);
  574.  
  575.          continue;
  576.  
  577.       }
  578.  
  579.       if (strcasecmp(code, "ADMIT-SENDER") == 0) 
  580.       {
  581.          strcpy(tmp,"admit-sender ");
  582.          tmp += strlen(tmp);
  583.  
  584.          if (admit_cnt == maxallowed)
  585.          {
  586.             printf("%d is the maximum number of clients that can be added to the admit sender list\n",
  587.             maxallowed);
  588.             exit(-1);
  589.          }
  590.  
  591.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  592.          {
  593.             printf ("ADMIT-SENDER paramater count error\n");
  594.             exit(-1);
  595.          }
  596.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  597.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  598.          
  599.          sprintf(tmp,"%d.%d.%d.%d ",hb,mh,ml,lb);
  600.          tmp += strlen(tmp);
  601.  
  602.          if ((admit_senders[admit_cnt++] = inet_addr(buf)) == -1)
  603.          {
  604.             printf("inet_addr: bad ADMIT-SENDER address\n");
  605.             exit(-1);
  606.          }
  607.          local_senders = 0;
  608.      continue;
  609.       }
  610.  
  611.       if (strcasecmp(code, "ADMIT") == 0) 
  612.       {
  613.          strcpy(tmp,"admit ");
  614.          tmp += strlen(tmp);
  615.  
  616.          if (restrict_cnt == maxallowed)
  617.          {
  618.             printf("%d is the maximum number of clients that can be added to the admit list\n",maxallowed);
  619.             exit(-1);
  620.          }
  621.  
  622.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  623.          {
  624.             printf ("ADMIT paramater count error\n");
  625.             exit(-1);
  626.          }
  627.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  628.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  629.          
  630.          sprintf(tmp,"%d.%d.%d.%d ",hb,mh,ml,lb);
  631.          tmp += strlen(tmp);
  632.  
  633.          status = scan_str(ad_buf,MSGBUF);
  634.  
  635.          if (status == -1)
  636.          {
  637.             printf ("admit message string does not end with // \n");
  638.             exit(-1);
  639.          }
  640.  
  641.          if (status == -2)
  642.          {
  643.             printf ("admit message length is greater then %d characters \n",MSGBUF);
  644.             exit(-1);
  645.          }
  646.  
  647.          sprintf(tmp,"%s\n",ad_buf);
  648.          tmp += strlen(tmp);
  649.  
  650.  
  651.          if ((restrict_list[restrict_cnt++] = inet_addr(buf)) == -1)
  652.          {
  653.             printf("inet_addr: bad ADMIT address\n");
  654.             exit(-1);
  655.          }
  656.          continue;
  657.       }
  658.  
  659.       if (strcasecmp(code, "CAP") == 0) 
  660.       {
  661.          strcpy(tmp,"cap ");
  662.          tmp += strlen(tmp);
  663.  
  664.          if ((cnt = fscanf(conf_fd, "%i %i",&cap,&hold_down)) != 2)
  665.          {
  666.             printf ("CAP paramater count error\n");
  667.             exit(-1);
  668.          }
  669.          printf("%d ",cap);
  670.  
  671.          sprintf(buf,"%d ",cap);
  672.  
  673.          sprintf(tmp,"%d ",cap);
  674.          tmp += strlen(tmp);
  675.  
  676.          if (hold_down < 1)
  677.             hold_down = 1;
  678.  
  679.          printf("%d ",hold_down);
  680.  
  681.          sprintf(buf,"%d ",hold_down);
  682.  
  683.          sprintf(tmp,"%d ",hold_down);
  684.          tmp += strlen(tmp);
  685.  
  686.          status = scan_str(cap_buf,MSGBUF);
  687.  
  688.          if (status == -1)
  689.          {
  690.             printf ("cap message string does not end with // \n");
  691.             exit(-1);
  692.          }
  693.  
  694.          if (status == -2)
  695.          {
  696.             printf ("cap message length is greater then %d characters \n",MSGBUF);
  697.             exit(-1);
  698.          }
  699.  
  700.          sprintf(tmp,"%s\n",cap_buf);
  701.          tmp += strlen(tmp);
  702.  
  703.          /* change to bytes per second plus a 20% fudge factor */
  704.  
  705.          cap = ((1024 * cap) /8);
  706.          cap += (cap * .2);
  707.  
  708.          /* change from minutes to seconds */
  709.          hold_down *= 60;   
  710.  
  711.          continue;
  712.       }
  713.  
  714.       if (strcasecmp(code, "DENY") == 0) 
  715.       {
  716.          strcpy(tmp,"deny ");
  717.          tmp += strlen(tmp);
  718.  
  719.          if (deny_cnt == maxallowed)
  720.          {
  721.             printf("%d is the maximum number of clients that can be added to the deny list\n",maxallowed);
  722.             exit(-1);
  723.          }
  724.  
  725.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  726.          {
  727.             printf ("DENY paramater count error\n");
  728.             exit(-1);
  729.          }
  730.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  731.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  732.          
  733.          sprintf(tmp,"%d.%d.%d.%d ",hb,mh,ml,lb);
  734.          tmp += strlen(tmp);
  735.  
  736.          status = scan_str(dy_buf,MSGBUF);
  737.  
  738.          if (status == -1)
  739.          {
  740.             printf ("deny message string does not end with // \n");
  741.             exit(-1);
  742.          }
  743.  
  744.          if (status == -2)
  745.          {
  746.             printf ("deny message length is greater then %d characters \n",MSGBUF);
  747.             exit(-1);
  748.          }
  749.  
  750.          sprintf(tmp,"%s\n",dy_buf);
  751.          tmp += strlen(tmp);
  752.  
  753.          if ((deny_list[deny_cnt++] = inet_addr(buf)) == -1)
  754.          {
  755.             printf("inet_addr: bad DENY address\n");
  756.             exit(-1);
  757.          }
  758.          continue;
  759.       }
  760.  
  761.  
  762.       if (strcasecmp(code, "SELF-REFLECT") == 0) 
  763.       {
  764.          strcpy(tmp,"self-reflect\n ");
  765.          tmp += strlen(tmp);
  766.          self_reflect = 1;
  767.          continue;
  768.       }
  769.  
  770.       if (strcasecmp(code, "NO-LOCAL-SENDERS") == 0) 
  771.       {
  772.          strcpy(tmp,"no-local-senders\n");
  773.          tmp += strlen(tmp);
  774.          local_senders = 0;
  775.          continue;
  776.       }
  777.  
  778.       if (strcasecmp(code, "LOG") == 0) 
  779.       {
  780.          strcpy(tmp,"log ");
  781.          tmp += strlen(tmp);
  782.  
  783.          if ((cnt = fscanf(conf_fd, "%s",tracefile)) != 1)
  784.          {
  785.             printf ("LOG paramater count error\n");
  786.             exit(-1);
  787.          }
  788.          printf("%s ",tracefile);
  789.  
  790.          sprintf(tmp,"%s\n",tracefile);
  791.          tmp += strlen(tmp);
  792.  
  793.          continue;
  794.       }
  795.  
  796.       if (strcasecmp(code, "OBTAIN-GENERAL-BCC") == 0) 
  797.       {
  798.          strcpy(tmp,"obtain-general-bcc ");
  799.          tmp += strlen(tmp);
  800.  
  801.          if (bcc_srv_cnt == MAXSRCREF)
  802.          {
  803.             printf("%d is the maximum number of OBTAIN-BCC reflectors allowed\n",MAXSRCREF);
  804.             exit(-1);
  805.          }
  806.  
  807.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i %i",&hb,&mh,&ml,&lb,&id)) != 5)
  808.          {
  809.             printf ("OBTAIN-GENERAL-BCC paramater count error\n");
  810.             exit(-1);
  811.          }
  812.  
  813.          printf("%d.%d.%d.%d %d ",hb,mh,ml,lb,id);
  814.          sprintf(buf,"%d.%d.%d.%d %d",hb,mh,ml,lb,id);
  815.          
  816.          sprintf(tmp,"%d.%d.%d.%d %d\n",hb,mh,ml,lb,id);
  817.          tmp += strlen(tmp);
  818.  
  819.          if ((bcc_server_list[bcc_srv_cnt] = inet_addr(buf)) == -1)
  820.          {
  821.             printf("inet_addr: bad OBTAIN-BCC address\n");
  822.             exit(-1);
  823.          }
  824.  
  825.          bcc_server_list_id[bcc_srv_cnt++] = id;
  826.  
  827.          continue;
  828.       }
  829.  
  830.       if (strcasecmp(code, "OBTAIN-BCC") == 0) 
  831.       {
  832.          strcpy(tmp,"obtain-bcc ");
  833.          tmp += strlen(tmp);
  834.  
  835.          if (bcc_srv_cnt == MAXSRCREF)
  836.          {
  837.             printf("%d is the maximum number of OBTAIN-BCC reflectors allowed\n",MAXSRCREF);
  838.             exit(-1);
  839.          }
  840.  
  841.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  842.          {
  843.             printf ("OBTAIN-BCC paramater count error\n");
  844.             exit(-1);
  845.          }
  846.  
  847.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  848.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  849.          
  850.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  851.          tmp += strlen(tmp);
  852.  
  853.          if ((bcc_server_list[bcc_srv_cnt++] = inet_addr(buf)) == -1)
  854.          {
  855.             printf("inet_addr: bad OBTAIN-BCC address\n");
  856.             exit(-1);
  857.          }
  858.  
  859.          continue;
  860.       }
  861.  
  862.       if (strcasecmp(code, "ADMIT-BCC-CLIENT") == 0) 
  863.       {
  864.          strcpy(tmp,"admit-bcc-client ");
  865.          tmp += strlen(tmp);
  866.  
  867.          if (bcc_clt_cnt == MAXSRCREF)
  868.          {
  869.             printf("%d is the maximum number of ADMIT-BCC-CLIENT reflectors allowed\n",MAXSRCREF);
  870.             exit(-1);
  871.          }
  872.  
  873.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  874.          {
  875.             printf ("ADMIT-BCC-CLIENT paramater count error\n");
  876.             exit(-1);
  877.          }
  878.  
  879.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  880.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  881.  
  882.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  883.          tmp += strlen(tmp);
  884.  
  885.          if ((bcc_client_list[bcc_clt_cnt++] = inet_addr(buf)) == -1)
  886.          {
  887.             printf("inet_addr: bad ADMIT-BCC-CLIENT address\n");
  888.             exit(-1);
  889.          }
  890.          continue;
  891.       }
  892.  
  893.       if (strcasecmp(code, "UNICAST-REF") == 0) 
  894.       {
  895.          strcpy(tmp,"unicast-ref ");
  896.          tmp += strlen(tmp);
  897.  
  898.          if (ref_ucast_cnt == MAXSRCREF)
  899.          {
  900.             printf("%d is the maximum number of UNICAST-REF reflectors allowed\n",MAXSRCREF);
  901.             exit(-1);
  902.          }
  903.  
  904.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  905.          {
  906.             printf ("UNICAST-REF paramater count error\n");
  907.             exit(-1);
  908.          }
  909.  
  910.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  911.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  912.          
  913.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  914.          tmp += strlen(tmp);
  915.  
  916.          if ((ref_ucast_list[ref_ucast_cnt++] = inet_addr(buf)) == -1)
  917.          {
  918.             printf("inet_addr: bad UNICAST-REF address\n");
  919.             exit(-1);
  920.          }
  921.  
  922.          continue;
  923.       }
  924.  
  925.       if (strcasecmp(code, "VAT-UC-PORT") == 0) 
  926.       {
  927.          strcpy(tmp,"vat-uc-port ");
  928.          tmp += strlen(tmp);
  929.  
  930.          if ((cnt = fscanf(conf_fd, " %i", &maven_port)) != 1)
  931.          {
  932.             printf ("VAT-UC-PORT paramater count error\n");
  933.             exit(-1);
  934.          }
  935.  
  936.          printf("%d ",maven_port);
  937.          sprintf(buf,"%d ",maven_port);
  938.  
  939.          sprintf(tmp,"%d\n",maven_port);
  940.          tmp += strlen(tmp);
  941.  
  942.          continue;
  943.       }
  944.  
  945.       if (strcasecmp(code, "NV-STREAMS") == 0) 
  946.       {
  947.          strcpy(tmp,"nv-streams ");
  948.          tmp += strlen(tmp);
  949.  
  950.          if ((cnt = fscanf(conf_fd, " %i", &nv_streams)) != 1)
  951.          {
  952.             printf ("NV-STREAMS paramater count error\n");
  953.             exit(-1);
  954.          }
  955.  
  956.          printf("%d ",nv_streams);
  957.          sprintf(buf,"%d ",nv_streams);
  958.  
  959.          sprintf(tmp,"%d\n",nv_streams);
  960.          tmp += strlen(tmp);
  961.  
  962.          continue;
  963.       }
  964.  
  965.       if (strcasecmp(code, "LOG-LIMIT") == 0) 
  966.       {
  967.          strcpy(tmp,"log-limit ");
  968.          tmp += strlen(tmp);
  969.  
  970.          if ((cnt = fscanf(conf_fd, " %i", &log_limit)) != 1)
  971.          {
  972.             printf ("LOG-LIMIT paramater count error\n");
  973.             exit(-1);
  974.          }
  975.  
  976.          printf("%d ",log_limit);
  977.          sprintf(buf,"%d ",log_limit);
  978.  
  979.          sprintf(tmp,"%d\n",log_limit);
  980.          tmp += strlen(tmp);
  981.  
  982.          continue;
  983.       }
  984.  
  985.       if (strcasecmp(code, "CONF-MGR") == 0) 
  986.       {
  987.          strcpy(tmp, "conf-mgr ");
  988.          tmp += strlen(tmp);
  989.  
  990.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i", &hb,&mh,&ml,&lb)) != 4)
  991.          {
  992.             printf("CONF-MGR parameter count error\n");
  993.             exit(-1);
  994.           }
  995.  
  996.           printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  997.           sprintf(buf, "%d.%d.%d.%d ",hb,mh,ml,lb);
  998.  
  999.           sprintf(tmp, "%d.%d.%d.%d\n",hb,mh,ml,lb);
  1000.           tmp += strlen(tmp);
  1001.  
  1002.           if ((god_ip = inet_addr(buf)) == -1)
  1003.           {
  1004.             printf("inet_addr: bad CONF-MGR address\n");
  1005.             exit(-1);
  1006.           }
  1007.  
  1008.           continue;
  1009.       }
  1010.  
  1011.       if (strcasecmp(code, "MOTD") == 0) 
  1012.       {
  1013.          strcpy(tmp,"motd \n");
  1014.          tmp += strlen(tmp);
  1015.  
  1016.          status = scan_str(motd_buf,MOTDBUF);
  1017.  
  1018.          if (status == -1)
  1019.          {
  1020.             printf ("MOTD message does not end with // \n");
  1021.             exit(-1);
  1022.          }
  1023.  
  1024.          if (status == -2)
  1025.          {
  1026.             printf ("maximum MOTD message length s %d\n",MOTDBUF);
  1027.             exit(-1);
  1028.          }
  1029.  
  1030.          sprintf(tmp,"%s\n",motd_buf);
  1031.          motd_len = strlen(motd_buf);
  1032.          tmp += motd_len;
  1033.  
  1034.          continue;
  1035.       }
  1036.  
  1037.  
  1038.       if (strcasecmp(code, "VAT-CONF-ID") == 0) 
  1039.       {
  1040.          strcpy(tmp,"vat-conf-id ");
  1041.          tmp += strlen(tmp);
  1042.  
  1043.          if ((cnt = fscanf(conf_fd, "%i",&vat_confid)) != 1)
  1044.          {
  1045.              printf ("VAT-CONF-ID paramater count error\n");
  1046.              exit(-1);
  1047.            }
  1048.  
  1049.         printf("%d ",vat_confid);
  1050.         sprintf(buf,"%d ",vat_confid);
  1051.         sprintf(tmp,"%d\n",vat_confid);
  1052.         tmp += strlen(tmp);
  1053.  
  1054.         continue;
  1055.       }
  1056.  
  1057.       if (strcasecmp(code, "VAT-MC-PORT") == 0)
  1058.       {
  1059. #ifdef MULTI
  1060.          strcpy(tmp,"vat-mc-port ");
  1061.          tmp += strlen(tmp);
  1062.  
  1063.          if ((cnt = fscanf(conf_fd, " %i", &vat_port)) != 1)
  1064.          {
  1065.             printf ("VAT-MC-PORT paramater count error\n");
  1066.             exit(-1);
  1067.          }
  1068.  
  1069.          printf("%d ",vat_port);
  1070.          sprintf(buf,"%d ",vat_port);
  1071.  
  1072.          sprintf(tmp,"%d\n",vat_port);
  1073.          tmp += strlen(tmp);
  1074.  
  1075.          /*assign the port numbers now...if we try this below and vat_port hasn't
  1076.            been set yet, then it will end up as 0 */
  1077.          vat_out_mcast.sin_port = htons(vat_port);
  1078.          vat_in_mcast.sin_port = htons(vat_port);
  1079. #else
  1080.          printf ("This copy of the reflector was not built with Multicast support\n");
  1081.          exit(-1);
  1082. #endif
  1083.  
  1084.          continue;
  1085.       }
  1086.  
  1087.  
  1088.  
  1089.       if (strcasecmp(code, "VAT-MC-OUT") == 0)
  1090.       {
  1091. #ifdef MULTI
  1092.          strcpy(tmp,"vat-mc-out ");
  1093.          tmp += strlen(tmp);
  1094.  
  1095.          if ((cnt = fscanf(conf_fd, "%i %i.%i.%i.%i",&vat_ttl,&hb,&mh,&ml,&lb)) != 5)
  1096.          {
  1097.             printf ("VAT-MC-OUT paramater count error\n");
  1098.             exit(-1);
  1099.          }
  1100.          printf("%d %d.%d.%d.%d ",vat_ttl,hb,mh,ml,lb);
  1101.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  1102.  
  1103.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  1104.          tmp += strlen(tmp);
  1105.  
  1106.          if ((vat_out_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  1107.          {
  1108.             printf("inet_addr: bad VAT-MC-OUT multicast address\n");
  1109.             exit(-1);
  1110.          }
  1111.          vat_out_mcast.sin_family = AF_INET;
  1112.  
  1113. #else
  1114.          printf ("This copy of the reflector was not built with Multicast support\n");
  1115.          exit(-1);
  1116. #endif
  1117.          continue;
  1118.       }
  1119.  
  1120.  
  1121.       if (strcasecmp(code, "VAT-MC-IN") == 0)
  1122.       {
  1123. #ifdef MULTI
  1124.          strcpy(tmp,"vat-mc-in ");
  1125.          tmp += strlen(tmp);
  1126.  
  1127.          if ((cnt = fscanf(conf_fd, "%i.%i.%i.%i",&hb,&mh,&ml,&lb)) != 4)
  1128.          {
  1129.             printf ("VAT-MC-IN paramater count error\n", cnt);
  1130.             exit(-1);
  1131.          }
  1132.          printf("%d.%d.%d.%d ",hb,mh,ml,lb);
  1133.          sprintf(buf,"%d.%d.%d.%d ",hb,mh,ml,lb);
  1134.  
  1135.          sprintf(tmp,"%d.%d.%d.%d\n",hb,mh,ml,lb);
  1136.          tmp += strlen(tmp);
  1137.  
  1138.          if ((vat_in_mcast.sin_addr.s_addr = inet_addr(buf)) == -1)
  1139.          {
  1140.             printf("inet_addr: bad vAT-MC-IN multicast address\n");
  1141.             exit(-1);
  1142.          }
  1143.          vat_in_mcast.sin_family = AF_INET;
  1144.  
  1145. #else
  1146.          printf ("This copy of the reflector was not built with Multicast support\n");
  1147.          exit(-1);
  1148. #endif
  1149.          continue;
  1150.       }
  1151.  
  1152.  
  1153.       printf ("Configuration file is damaged: Bad CODE value line %d\n",clincnt);
  1154.       exit(-1);
  1155.    }
  1156.    printf("\n");
  1157.    fflush(stdout);
  1158.    close(conf_fd);
  1159. }
  1160.  
  1161.  
  1162. short scan_str(buf,maxlen)
  1163.    char *buf;
  1164.    short maxlen;
  1165. {
  1166.    short          len;
  1167.    char           c,c1,c2;
  1168.  
  1169.    len = 0;
  1170.  
  1171.    while (1)
  1172.    {
  1173.       if ((c = fgetc(conf_fd)) == EOF)
  1174.          return(-1);
  1175.  
  1176.       if ((c == '\n') || (c == '\r'))
  1177.       {
  1178.          if ((c1 = fgetc(conf_fd)) == EOF)
  1179.             return(-1);
  1180.  
  1181.          if (c1 == '/')
  1182.          {
  1183.             if ((c2 = fgetc(conf_fd)) == EOF)
  1184.                return(-1);
  1185.  
  1186.             if (c2 == '/')
  1187.             {
  1188.                *buf++ = 0;
  1189.                return(0);
  1190.             }
  1191.  
  1192.             if ((len = len+3) >= maxlen)
  1193.                return(-2);
  1194.  
  1195.             *buf++ = c;
  1196.             printf("%c",c);
  1197.    
  1198.             *buf++ = c1;
  1199.             printf("%c",c1);
  1200.  
  1201.             *buf++ = c2;
  1202.             printf("%c",c2);
  1203.          }
  1204.          else
  1205.          {
  1206.             if ((len = len+2) >= maxlen)
  1207.                return(-2); 
  1208.  
  1209.             *buf++ = c;
  1210.             printf("%c",c);
  1211.  
  1212.             *buf++ = c1;
  1213.             printf("%c",c1);
  1214.          }
  1215.       }
  1216.       else
  1217.       {
  1218.          if ((len = len+1) >= maxlen)
  1219.             return(-2);
  1220.  
  1221.          *buf++ = c;
  1222.          printf("%c",c);
  1223.       }
  1224.    }
  1225. }
  1226.